//pages/index/styletest.js
var api=require('../../utils/api.js')
var istap=0;
Page({
    data:{
        city: ['武汉','十堰','荆门','襄阳','荆州','宜昌','孝感','黄石','咸宁','恩施','黄冈','鄂州','天门','信阳','洛阳'],
        steps: ['view1','view2','view3','view4','view5'],
        toView: 0,
        isscroll: false,
        selecteditems: [-1,-1,-1,-1,-1],
        index: null,
        inputmobile: ''
    },
    bindCitysChange(e){
    	this.setData({
    		index: e.detail.value
    	})
    },
    nextstep(e){
        if(this.data.selecteditems[this.data.toView]==-1){
            wx.showToast({
                title: '至少选择一个选项',
                icon: 'none'
            })
            return false;
        }else if(this.data.index==null){
            wx.showToast({
                title: '请选择您的城市',
                icon: 'none;'
            })
            return false;
        }
        if(istap==0 && this.data.toView<this.data.selecteditems.length-1){
            istap=1;
            this.setData({
                isscroll: true
            })
            this.setData({
                toView: this.data.toView+1
            })
        }
    },
    prestep(e){
    	console.log(istap)
    	if(istap==0 && this.data.toView>0){
    		istap=1;
    		this.setData({
    			isscroll: true
    		})
    		this.setData({
    			toView: this.data.toView-1
    		})
    	}
    },
    onscoll(e){
    	console.log(e)
    	console.log(e.detail.scrollleft)
        console.log(Math.abs(e.detail.deltaX)*this.data.toView)
        if(Math.abs(e.detail.deltax)*this.data.toView-e.detail.scrollLeft==0){
            this.setData({
                isscroll:false;
            })
            istap=0
        }
    },

    touchstart(e){
        if(this.data.siscroll){
            this.setData({
                isscoll:false
            })
        }
    },
    selectitem(e){
        let id=e.target.dataset.step;

        if(this.data.selecteditems[step]==id){
            this.data.selecteditems[step]=-1;
        }else{
            this.data.selecteditems[step]=id
        }
        this.setData({
            selecteditems: this.data.selecteditems
        })
    },

    formSubmit(e){
        if(this.data.selecteditems[this.data.toView]==-1){
            wx.showToast({
                title: "至少选择一个选项",
                icon: "node"
            })
            return false;
        }

        api.post({
            url: '/portal/diyform/insert',
            data: {
                this.data.citys[this.data.index],
                name: '',
                source: "风格测试",
                styleimg: this.data.selecteditems[this.data.toView]
            },
            success: data=> {
                if (data.code == "1") {
                    wx.showToast({title: '报名成功', icon: 'success'})

                }
                if (data.code == "0") {
                    wx.showToast({title: data.msg, icon: 'none'})
                }
            }
        })
    },
    inputmobile(e){
        this.setData({
            inputmobile: e.detail.value
        })
    },
    onLoad: function(opstions){}, //页面监听加载

    onReady: function(){}, //页面监听渲染

    onShow: function(){}, //页面监听显示

    onHide: function(){}, //页面监听隐藏

    onUnload: function(){}, //监听页面卸载

    onPullDownRefreash: function(){}, //监听用户下拉动作

    onReachBottom: function(){}, //监听页面触底事件

    onShareAppMessage: function(){} //用户触发分享
})